import { createRouter, createWebHistory } from 'vue-router'

// 导入页面组件
import User from '../views/User.vue'

// 定义路由
const routes = [
  {
    path: '/',
    name: 'Home',
    component: User,
    meta: {
      title: '用户数据管理'
    }
  }
]

// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes
})

// 全局前置守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  document.title = to.meta.title || 'Vue Element Plus CRUD'
  next()
})

export default router